//
//  main.m
//  NSMutableDictionary
//
//  Created by wenjim on 17/10/24.
//  Copyright © 2017年 WenJim. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    
    
    // 1. 创建一个空的字典
    NSMutableDictionary * dicM = [NSMutableDictionary dictionary];
    NSLog(@"dicM = %@",dicM);
    // 2. 如何添加
    [dicM setObject:@"cwj" forKey:@"name"];
    NSLog(@"dicM = %@",dicM);
    // 会将传入字典中所有的键值对取出来添加到dicM中
    [dicM setValuesForKeysWithDictionary:@{@"age":@"26",@"height":@"1.75"}];
    NSLog(@"dicM = %@",dicM);
    
    // 3.如何获取
    NSString * name = [dicM objectForKey:@"name"];
    NSLog(@"name = %@ - %@",name,dicM[@"name"]);
    
    // 4.如何删除
    [dicM removeObjectForKey:@"name"];
    NSLog(@"dicM = %@",dicM);
    
//    [dicM removeObjectsForKeys:@[@"age"]];
//    NSLog(@"dicM = %@",dicM);
    
//    [dicM removeAllObjects];
//    NSLog(@"dicM = %@",dicM);
    
    // 5.如何修改
    // 如果利用setObject 方法给同名的 key赋值，那么新值会覆盖旧值
    [dicM setObject:@"27" forKey:@"age"];
    NSLog(@"dicM = %@",dicM);
    dicM[@"age"] = @"28";
    NSLog(@"dicM = %@",dicM);
    
    
    // 注意点
    // 1.不能使用@{}来创建一个可变的字典
    NSMutableDictionary * dict = @{@"name":@"cwj",@"age":@"23"};
//    [dict setObject:@"27" forKey:@"age"];
    NSLog(@"dict = %@",dict);
    
    // 2.如果是不可变数组，那么key不能相同
    // 如果是不可变字典出现了同名的key，那么后面的key对应的值不会被保存
    // 如果是在可变字典中，后面的会覆盖前面的
    NSDictionary * dic = @{@"name":@"cwj",@"name":@"zbc"};
    NSLog(@"dic = %@",dic);
    
    NSMutableDictionary * dicMu = [NSMutableDictionary dictionaryWithObjects:@[@"cwj",@"zbc"] forKeys:@[@"name",@"name"]];
    NSLog(@"dicMu = %@",dicMu);
    
    return 0;
}
